#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
简单的MCP计算器服务测试脚本
"""

import asyncio
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client

async def simple_test():
    """简单测试MCP服务器功能"""
    server_params = StdioServerParameters(
        command="python",
        args=["main.py"]
    )
    
    try:
        async with stdio_client(server_params) as (read, write):
            async with ClientSession(read, write) as session:
                await session.initialize()
                
                print("=== MCP增强版计算器服务测试 ===")
                
                # 测试基础运算
                print("\n✅ 测试加法:")
                result = await session.call_tool("add", {"a": 10, "b": 5})
                print(f"10 + 5 = {result.content[0].text}")
                
                print("\n✅ 测试除法:")
                result = await session.call_tool("divide", {"a": 15, "b": 3})
                print(f"15 ÷ 3 = {result.content[0].text}")
                
                # 测试新增功能
                print("\n✅ 测试角度转弧度:")
                result = await session.call_tool("degrees_to_radians", {"degrees": 90})
                print(f"90° = {result.content[0].text} 弧度")
                
                print("\n✅ 测试指数函数:")
                result = await session.call_tool("exp", {"x": 1})
                print(f"e^1 = {result.content[0].text}")
                
                print("\n✅ 测试向上取整:")
                result = await session.call_tool("ceil", {"x": 3.2})
                print(f"ceil(3.2) = {result.content[0].text}")
                
                print("\n✅ 测试四舍五入:")
                result = await session.call_tool("round_number", {"x": 3.14159, "digits": 2})
                print(f"round(3.14159, 2) = {result.content[0].text}")
                
                # 测试问候功能
                print("\n✅ 测试问候功能:")
                result = await session.call_tool("say_hello", {"name": "李宛津"})
                print(f"问候: {result.content[0].text}")
                
                # 测试错误处理
                print("\n⚠️ 测试错误处理 - 除零:")
                try:
                    result = await session.call_tool("divide", {"a": 10, "b": 0})
                    print(f"除零结果: {result.content[0].text}")
                except Exception as e:
                    print(f"正确捕获除零错误: {e}")
                
                print("\n🎉 测试完成！服务运行正常。")
                
    except Exception as e:
        print(f"❌ 测试出错: {e}")

if __name__ == "__main__":
    asyncio.run(simple_test())